#include <fstream>
#include <string>
#include "StringTest.h"

using namespace SystemTool;

void LogFile(std::string strMsg)
{
    std::string strFilePath = "/Users/tangyingzhong/Desktop/12.log";
    std::fstream os(strFilePath,std::ios::app);
    os << strMsg << "\n";
    os.close();
}

void TestCopy(String strData)
{
    std::string strT = strData.Data();
    LogFile(strT);
}

void StringTest()
{
    std::string strData = "挑奖金高的项目做";
    std::wstring strWData = L"只会对着电脑戳戳，不知我们的辛苦";

    String strData1 = strData;
    LogFile(strData1.Data());
    wprintf(L"%s\n",strData1.WData().c_str());

    strData1 = strWData;
    LogFile(strData1.Data());
    wprintf(L"%s\n",strData1.WData().c_str());

    String str1 = "发货就是看到回复";
    LogFile(str1.Data());

    String str2 = L"为什么没有证书";
    LogFile(str2.Data());

    String str3 = String("胡卡很舒服");
    LogFile(str3.Data());

    String str4 = String(L"大袋哪壶");
    LogFile(str4.Data());

    str4 = str1;
    LogFile(str4.Data());

    TestCopy("这么说就行");
    TestCopy(L"居然崩溃了");
    TestCopy(strData);
    TestCopy(str1);

    String p("fhskjdhfsuhfi");
    p = p.MakeUpper();
    LogFile(p.Data());

    String p2("GGHJJHHUHYIUTUYYT");
    p2 = p2.MakeLower();
    LogFile(p2.Data());

    p = p.Append(-98098);
    LogFile(p.Data());

    p = p.Append(8980);
    LogFile(p.Data());

    p = p.Append(89.43f);
    LogFile(p.Data());

    p = p.Append(12.78);
    LogFile(p.Data());

    p = p.Append("JKM");
    LogFile(p.Data());

    p = p.Append(L"对别人的尊重");
    LogFile(p.Data());

    p = "";
    p = p + "anxingongzuo";
    LogFile(p.Data());

    p = "";
    p = p + "山峰";
    LogFile(p.Data());

    p = "";
    p = p + "99.7f";
    LogFile(p.Data());

    p = "";
    p = p + "8.97";
    LogFile(p.Data());

    p = "玛丽亚";
    int iRet = p.IsEmpty() ? 1 :0;
    std::string strRet = std::to_string(iRet);
    LogFile(strRet);

    int iRet2 = p.IsContain("玛丽") ? 1 :0;
    std::string strRet2 = std::to_string(iRet2);
    LogFile(strRet2);

    String pp1("玛丽亚");
    int iRet4 = p == pp1 ? 1 :0;
    std::string strRet4 = std::to_string(iRet4);
    LogFile(strRet4);

    iRet4 = p != pp1 ? 1 :0;
    strRet4 = std::to_string(iRet4);
    LogFile(strRet4);

    String T1(L"表示");
    wchar_t ch = T1[0];

    T1 = "fight";
    ch = T1[0];

    T1 = "飞机#fjdh#哈哈哈#kkkk";
    std::vector<String> vTable;
    T1.Split("#",vTable);
    for (size_t index = 0; index < vTable.size(); index++)
    {
        LogFile(vTable[index].Data());
    }

    String T2("tyu仿佛好");
    int iLen = T2.Length();
    std::string strLen = std::to_string(iLen);
    LogFile(strLen);

    T2 = "jjjjjkkkkkdfffwerrrrwr";
    T2 = T2.SubStr(4,5);
    TestCopy(T2);

    T2 = "工作第一是吧";
    String strT3 = T2.Left(2);
    TestCopy(strT3);

    String strT4 = T2.Right(2);
    TestCopy(strT4);

    T2 = "jjjjjkkkkkdfffwerrrrwr";
    T2.Replace("jjjjj","WW");
    TestCopy(T2);

    T2.Replace(6,5,"GG");
    TestCopy(T2);

    T2 = "hello,you do ok";
    int iPos = T2.Find("ll");
    strLen = std::to_string(iPos);
    LogFile(strLen);

    T2 = "/Users/tangyingzhong/Desktop/MyCode/12.log";
    iPos = T2.FindLastOf("/");
    strLen = std::to_string(iPos);
    LogFile(strLen);

    String T7 = "89";
    int iData = T7.ToInt();
    strLen = std::to_string(iData);
    LogFile(strLen);

    T7 = "89.7";
    float fData = T7.ToFloat();
    strLen = std::to_string(fData);
    LogFile(strLen);

    String T9 = T7.FromInt(88);
    TestCopy(T9);

    T9 = T7.FromFloat(4.67);
    TestCopy(T9);

    String strData11 = "fjkldfjTTT";
    strData11 += "UUUUUU";
    std::cout << strData11.Data() << std::endl;

    String strData22 = "FFFFFF";
    if (strData11 == strData22)
    {
        std::cout << "Same\n";
    }

    if(strData11 != strData22)
    {
        std::cout << "Not Same\n";
    }

    String strT112 = "房价快速的恢复|fhjoshdfj|饭都是废话";
    strT112 = strT112.SubStr(0, strT112.Length()-3);
    std::cout << strT112.Data() << std::endl;

    strT112.Replace("|"," ");
    std::cout << strT112.Data() << std::endl;

    String strGG = "123124141414141";
    long long data = strGG.ToLongLong();
    std::cout << data << std::endl;

    return;
}
